package com.flyduck.mall.oms.h5.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.flyduck.mall.oms.h5.vo.*;
import com.flyduck.ss.common.core.domain.R;
import com.flyduck.mall.common.web.core.BaseController;


import com.flyduck.mall.oms.h5.service.H5OrderService;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program: vueshop
 * @description:
 * @author: flyduck
 * @create: 2024-05-20 20:40
 **/
@RestController
@RequestMapping("/order/h5/order")
public class H5OrderController extends BaseController {

    @Resource
    private H5OrderService h5OrderService;

    //@Login
    @PostMapping("previewOrder")
    public R<H5OrderPreviewRespVO> previewOrder(@RequestBody H5OrderPreviewReqVO h5OrderPreviewReqVO){
        H5OrderPreviewRespVO appOrderPreviewRespVO = h5OrderService.previewOrder(h5OrderPreviewReqVO);
        return R.ok(appOrderPreviewRespVO);
    }

    //@Login
    //@NoRepeatSubmit
    @PostMapping("createOrder")
    public R<String> createOrder(@RequestBody H5OrderCreateReqVO h5OrderCreateReqVO){
        String orderSn = h5OrderService.createOrder(h5OrderCreateReqVO);
        return R.ok(orderSn);
    }

    //@Login
    @GetMapping("/getOrderTotalCount")
    public R<H5OrderTotalCountRespVO> getOrderTotalCount(){
        H5OrderTotalCountRespVO h5OrderTotalCountRespVO = h5OrderService.getOrderTotalCount();
        return R.ok(h5OrderTotalCountRespVO);
    }

    //@Login
    @GetMapping("/getOrderPageByStatus")
    public R<Page<H5OrderRespVO>> getOrderPageByStatus(Integer status){
        return R.ok(h5OrderService.getOrderPageByStatus(getPage(),status));
    }

    //@Login
    @GetMapping("/getOrderDetailsById/{id}")
    public R<H5OrderDetailsRespVO> getOrderDetailsById(@PathVariable("id") Long id){
        return R.ok(h5OrderService.getOrderDetailsById(id));
    }

    //@Login
    @PostMapping("/cancelOrderById/{id}")
    public R<Void> cancelOrderById(@PathVariable("id")Long id){
        h5OrderService.cancelOrderById(id);
        return R.ok();
    }

    //@Login
    @PostMapping("/deleteById/{id}")
    public R<Void> deleteById(@PathVariable("id")Long id){
        h5OrderService.deleteById(id);
        return R.ok();
    }



    //@Login
    @PostMapping("/confirmOrderById/{id}")
    public R<Void> confirmOrderById(@PathVariable("id")Long id){
        h5OrderService.confirmOrderById(id);
        return R.ok();
    }
}
